<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt" %>
<form class="" id="saveForm">
<div class="row">
	<div class="col-md-12">
	<div class="box box-info">
           <div class="box-header with-border">
             <h3 class="box-title">菜单管理 </h3>
           </div>
           <!-- /.box-header -->
             <div class="box-body form-horizontal">
               <div class="form-group">
                 <label for="inputEmail3" class="col-sm-2 control-label">菜单名称</label>
                 <div class="col-sm-3">
                   <input type="text" class="form-control" name="name" id="name" value="${menu.name }">
                 </div>
               </div>
               <div class="form-group">
                 <label for="inputEmail3" class="col-sm-2 control-label">模块</label>
                 <div class="col-sm-3">
                   <input type="text" class="form-control" name="module" value="${menu.module }">
                 </div>
               </div>
               <div class="form-group">
                 <label for="inputEmail3" class="col-sm-2 control-label">controller</label>
                 <div class="col-sm-3">
                   <input type="text" class="form-control" name="controller" value="${menu.controller }">
                 </div>
               </div>
               <div class="form-group">
                 <label for="inputEmail3" class="col-sm-2 control-label">action</label>
                 <div class="col-sm-3">
                   <input type="text" class="form-control" name="action" value="${menu.action }">
                 </div>
               </div>
               <div class="form-group">
                 <label for="inputEmail3" class="col-sm-2 control-label">其他参数</label>
                 <div class="col-sm-3">
                   <input type="text" class="form-control" name="param" value="${menu.param }">
                 </div>
               </div>
               <div class="form-group">
                 <label for="inputEmail3" class="col-sm-2 control-label">排序</label>
                 <div class="col-sm-3">
                   <input type="text" class="form-control" name="sort" value="${menu.sort }">
                 </div>
               </div>
               <div class="form-group">
                 <label for="inputEmail3" class="col-sm-2 control-label">上级菜单</label>
                 <div class="col-sm-3">
                 	<select name="parentid" id="parentid" class="form-control select2">
                 		<option value="0">==一级菜单==</option>
	                 	<c:forEach items="${menuList }" var="list">
	                 		<option value="${list.id }">${list.name }</option>
	                 	</c:forEach>
                 	</select>
                 </div>
               </div>
               
               <div class="box-footer">
                <a class="btn btn-info save">保存</a>
                <c:if test="${menu.id != null}">
                <a class="btn btn-danger" onclick="del('${menu.id}')">删除</a>
                </c:if>
                <a class="btn btn-default cancel" >取消</a>
             </div>
              <!-- /.box-body -->
         	</div>
         </div>
       </div>
     <input type="hidden" name="id" id="m_id" value="${menu.id }">
</form>
<script>
	$('#parentid').val('${menu.parentid}');

	function del(id){
		layer.confirm('确定删除么?', function(){ 
			$.post(path+'permission/menu/del',{id:id},function(data){
				if(data>0){
					layer.msg('删除成功', {
              		  closeBtn: 0
              		}, function(){
              			location.href = path+'permission/menu/list';
              		});
				}
			});
		});
	}
	
	$('.cancel').on('click',function(){
		location.href = path+'permission/menu/list';
	});
	$('.save').on('click',function(){
		var name = $('#name').val();
		if(!name){
			layer.msg("请填写菜单名称！");return;
		}
		
		$.ajax({
			type: "post", 
            url: path+"permission/menu/merge",
            data:$('#saveForm').serialize(),
            dataType: "json",
            success: function(data){
            	if(data > 0){
            		layer.msg('保存成功', {
              		  closeBtn: 0
              		}, function(){
	            		location.href = path+'permission/menu/list';
              		});
            	}else{
            		alert('保存失败！');
            	}
            }
		});
	});
</script>